package com.qf.consumer;

import com.qf.dao.impl.Producer;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.InvocationHandler;

import java.lang.reflect.Method;

/**
 * @ClassName Demo01
 * @Description TODO
 * @Author 86181
 * @Date 2022/8/31 20:56
 * @Version 1.0
 **/
public class Demo01 {
    public static void main(String[] args) {
        final Producer producer=new Producer();
        producer.buyProduct("厂家");

        Producer o=(Producer)   Enhancer.create(producer.getClass(), new InvocationHandler() {
           public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
               if ("buyProduct".equals(method.getName())){
                   System.out.println("业务逻辑增强");
                   //执行目标方法
                   method.invoke(producer,objects);
               }
                return null;
            }
        });
        o.buyProduct("代理");
    }
}
